﻿using Dapper;
using Dapper.Abstractions;

namespace DataAccess.Api.Endpoints.Blog
{
	public class Count: IEndpoint
	{
		public void MapEndpoint(IEndpointRouteBuilder endpoints)
		{
			endpoints.MapGet("api/blogs/count", async (IDbConnectionFactory dbConnectionFactory) =>
			{
				using var connection = await dbConnectionFactory.CreateConnectionAsync();
				var count = await connection.QueryAsync<int>("SELECT COUNT(*)as row_count FROM blogs");
				return Results.Ok(count);
			})
			.WithName("BlogCount")
			.WithTags(Tags.Blog);
		}
		
	}
}
